***** REGRESSIONS AT LOAN LEVEL FOR RFS REVISION

run "essentials_Tables_1_to_8.do"
					
	
		*** Regression Tables
				
		* Table 2A
		{
		    foreach y in 225 {
				foreach x in sd {	
				
				local regnum = 1	
				
				reghdfe d_LTI pol_treated treated_sd policy $bank_controls $loan_controls if time <= `y', absorb(localauth_time localauth_group) vce(cluster localauth_3 group_time) 
				gen reg_sample = 1 if e(sample) == 1
				
					
					eststo r`regnum': reghdfe d_LTI pol_treated treated_sd policy if time <= `y' & reg_sample == 1, absorb(aaa) vce(cluster localauth_3 group_time) 
						local regnum = `regnum' + 1	
						* Loan controls
						eststo r`regnum': reghdfe d_LTI pol_treated treated_sd policy $loan_controls  if time <= `y' & reg_sample == 1, absorb(aaa) vce(cluster localauth_3 group_time)  
							quietly estadd local borr_controls "Yes": r`regnum'
							local regnum = `regnum' + 1
						* + Bank controls FE
						eststo r`regnum': reghdfe d_LTI pol_treated treated_sd policy $bank_controls $loan_controls  if time <= `y' & reg_sample == 1, absorb(aaa) vce(cluster localauth_3 group_time)  
							quietly estadd local borr_controls "Yes": r`regnum'
							quietly estadd local bank_controls "Yes": r`regnum'
							local regnum = `regnum' + 1
						* + LA*BAnk
						eststo r`regnum': reghdfe d_LTI pol_treated treated_sd policy $bank_controls $loan_controls  if time <= `y' & reg_sample == 1, absorb(localauth_group) vce(cluster localauth_3 group_time) 
							quietly estadd local fixed_lb "Yes": r`regnum'
							quietly estadd local borr_controls "Yes": r`regnum'
							quietly estadd local bank_controls "Yes": r`regnum'
							local regnum = `regnum' + 1
						* + Time controls
						eststo r`regnum': reghdfe d_LTI pol_treated treated_sd policy $bank_controls $loan_controls if time <= `y' & reg_sample == 1, absorb(time localauth_group) vce(cluster localauth_3 group_time) 
							quietly estadd local fixed_t "Yes": r`regnum'
							quietly estadd local fixed_lb "Yes": r`regnum'
							quietly estadd local borr_controls "Yes": r`regnum'
							quietly estadd local bank_controls "Yes": r`regnum'
							local regnum = `regnum' + 1	
						
								
				
				drop reg_sample
				
				}
			}
			
					#delimit ;
					esttab r1 r2 r3 r4 r5 using Table_2A.tex, label replace nonotes se keep(pol_treated) booktabs
					s(N r2 borr_controls bank_controls fixed_lb fixed_t, label("Observations" "\(R^{2}\)" "Borrower, Loan Controls" "Bank Controls" "Local area\$\times\$Bank FE" "Time FE")) 
					mgroups("\$\leftarrow\mbox{Dummy for high LTI loans}(\mathbb{D}\mbox{(LTI}\geq\mbox{4.5))}\rightarrow\$", pattern(1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) lhs("Variable")) 
					nodepvars nomtitles;
					#delimit cr	
			
		}
		
		* Table 2B
		{
		    
				foreach y in 225 {
					foreach x in sd {
						
					local regnum = 1	
					
					reghdfe interest pol_treated policy treated_sd $bank_controls $loan_controls if time <= `y', absorb(time localauth_group) vce(cluster localauth_3 group_time) 
					gen reg_sample = 1 if e(sample) == 1
					
					
						eststo r`regnum': reghdfe interest pol_treated policy treated_sd if time <= `y' & reg_sample == 1 & d_LTI == 0, absorb(aaa) vce(cluster localauth_3 group_time)
								local regnum = `regnum' + 1					
						eststo r`regnum': reghdfe interest pol_treated policy treated_sd if time <= `y' & reg_sample == 1 & d_LTI == 1, absorb(aaa) vce(cluster localauth_3 group_time)
								local regnum = `regnum' + 1
							
							*** VERSION 1
							* No controls
							eststo r`regnum': reghdfe interest pol_treated_hLTI pol_treated pol_hLTI treated_hLTI treated_sd policy d_LTI if time <= `y' & reg_sample == 1, absorb(aaa) vce(cluster localauth_3 group_time)  
								local regnum = `regnum' + 1	
							* Only loan controls
							eststo r`regnum': reghdfe interest pol_treated_hLTI pol_treated pol_hLTI treated_hLTI treated_sd policy d_LTI $loan_controls if time <= `y' & reg_sample == 1, absorb(aaa) vce(cluster localauth_3 group_time)  
								quietly estadd local borr_controls "Yes": r`regnum'
								local regnum = `regnum' + 1	
							* Bank and Loan controls
							eststo r`regnum': reghdfe interest pol_treated_hLTI pol_treated pol_hLTI treated_hLTI treated_sd policy d_LTI $bank_controls $loan_controls if time <= `y' & reg_sample == 1, absorb(aaa) vce(cluster localauth_3 group_time)  
								quietly estadd local borr_controls "Yes": r`regnum'
								quietly estadd local bank_controls "Yes": r`regnum'
								local regnum = `regnum' + 1
							* + LA*bank
							eststo r`regnum': reghdfe interest pol_treated_hLTI pol_treated pol_hLTI treated_hLTI treated_sd policy d_LTI $bank_controls $loan_controls if time <= `y' & reg_sample == 1, absorb(localauth_group) vce(cluster localauth_3 group_time) 
								quietly estadd local fixed_lb "Yes": r`regnum'
								quietly estadd local borr_controls "Yes": r`regnum'
								quietly estadd local bank_controls "Yes": r`regnum'
								local regnum = `regnum' + 1	

							* + LA*Bank + time
							eststo r`regnum': reghdfe interest pol_treated_hLTI pol_treated pol_hLTI treated_hLTI treated_sd policy d_LTI $bank_controls $loan_controls if time <= `y' & reg_sample == 1, absorb(localauth_group time) vce(cluster localauth_3 group_time) 
								quietly estadd local fixed_t "Yes": r`regnum'
								quietly estadd local fixed_lb "Yes": r`regnum'
								quietly estadd local borr_controls "Yes": r`regnum'
								quietly estadd local bank_controls "Yes": r`regnum'
								local regnum = `regnum' + 1	
								
					drop reg_sample
				
					}
				}
				
					#delimit ;
					esttab r1 r2 r3 r4 r5 r6 r7 using Table_2B.tex, label replace nonotes se keep(pol_treated pol_treated_hLTI) booktabs
					s(N r2 borr_controls bank_controls fixed_lb fixed_t, label("Observations" "\(R^{2}\)" "Borrower, Loan Controls" "Bank Controls" "Local area\$\times\$Bank FE" "Time FE")) 
					mgroups("\$\leftarrow\mbox{Interest rate}\rightarrow\$", pattern(1 0 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) lhs("Variable")) 
					nodepvars nomtitles;
					#delimit cr	
					
	
					* clear estimates
					eststo clear
			
		}
		
		* Table 3
		{
		    
			*** By income quintiles
			foreach nuts in 2 {
				
				local regnum = 1
				
				foreach z of numlist 1(1)5 {			
					foreach y in 225 {
						foreach x in sd {
						
							eststo r`regnum': reghdfe d_income_`z'_v`nuts' pol_treated treated_sd policy $bank_controls $loan_controls if d_LTI == 1 & time <= `y', absorb(time localauth_group) vce(cluster localauth_3 group_time) 
								quietly estadd local fixed_t "Yes": r`regnum'
								quietly estadd local fixed_lb "Yes": r`regnum'
								quietly estadd local borr_controls "Yes": r`regnum'
								quietly estadd local bank_controls "Yes": r`regnum'
								local regnum = `regnum' + 1	
							
						}	
					}
				}
				
				#delimit ;
				esttab r1 r2 r3 r4 r5 using Table_3A.tex, label replace nonotes se keep(pol_treated) booktabs
				s(N r2 borr_controls bank_controls fixed_lb fixed_t, label("Observations" "\(R^{2}\)" "Borrower, Loan Controls" "Bank Controls" "Local area\$\times\$Bank FE" "Time FE")) 
				mgroups("\$\leftarrow \mbox{Dummy for income quintiles(}\mathbb{D}\mbox{(Inc=j))} \rightarrow\$", pattern(1 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) lhs("Variable")) 
				nodepvars nomtitles;
				#delimit cr	
				
				* clear estimates
				eststo clear
			
			}
			
		
		}
				
		* Table 4
		{
		    
			local regnum = 1
				foreach z of numlist 1(1)5 {			
					foreach y in 225 {
						foreach x in sd {
						
							eststo r`regnum': reghdfe d_income_1_v2 pol_treated treated_sd policy $bank_controls $loan_controls if LTI_band == `z' & time <= `y', absorb(time localauth_group) vce(cluster localauth_3 group_time) 
								quietly estadd local fixed_t "Yes": r`regnum'
								quietly estadd local fixed_lb "Yes": r`regnum'
								quietly estadd local borr_controls "Yes": r`regnum'
								quietly estadd local bank_controls "Yes": r`regnum'
								local regnum = `regnum' + 1							
						}	
					}
				}	
				
					eststo r`regnum': reghdfe d_income_1_v2 pol_treated treated_sd policy $bank_controls $loan_controls if time <= 225, absorb(time localauth_group) vce(cluster localauth_3 group_time)
						quietly estadd local fixed_t "Yes": r`regnum'
						quietly estadd local fixed_lb "Yes": r`regnum'
						quietly estadd local borr_controls "Yes": r`regnum'
						quietly estadd local bank_controls "Yes": r`regnum'
						local regnum = `regnum' + 1
					eststo r`regnum': reghdfe log_loan pol_treated treated_sd policy $bank_controls $loan_controls if time <= 225 & d_income_1_v2 == 1, absorb(time localauth_group) vce(cluster localauth_3 group_time) 
						quietly estadd local fixed_t "Yes": r`regnum'
						quietly estadd local fixed_lb "Yes": r`regnum'
						quietly estadd local borr_controls "Yes": r`regnum'
						quietly estadd local bank_controls "Yes": r`regnum'
						local regnum = `regnum' + 1
					eststo r`regnum': reghdfe log_loan pol_treated treated_sd policy $bank_controls $loan_controls if time <= 225 & d_income_1_v2 != 1, absorb(time localauth_group) vce(cluster localauth_3 group_time) 
						quietly estadd local fixed_t "Yes": r`regnum'
						quietly estadd local fixed_lb "Yes": r`regnum'
						quietly estadd local borr_controls "Yes": r`regnum'
						quietly estadd local bank_controls "Yes": r`regnum'
						local regnum = `regnum' + 1	
					
	
								
					#delimit ;
					esttab r1 r2 r3 r4 r5 r6 r7 r8 using Table_4.tex, label replace nonotes se keep(pol_treated) booktabs
					s(N r2 borr_controls bank_controls fixed_lb fixed_t,label("Observations" "\(R^{2}\)" "Borrower, Loan Controls" "Bank Controls" "Local area\$\times\$Bank FE" "Time FE")) 
					mgroups("\$\leftarrow \mbox{Dummy for low-income borrowers (}\mathbb{D}\mbox{(Inc=I))} \rightarrow\$" "\$\log\$(Loan Size)", pattern(1 0 0 0 0 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) lhs("Variable")) 
					nodepvars nomtitles;
					#delimit cr	
					
					* clear estimates
					eststo clear
			
		}
		
		* Table 5
		{
		    
			foreach y in 225 {
				foreach x in sd {
					
				local regnum = 1	
				

				* All loans to unconstrained kenders
				reghdfe d_LTI pol_Mshare policy Mshare $bank_controls $loan_controls if time <= `y' & treated_sd == 0, absorb(localauth_group time) vce(cluster localauth_3 group_time) 
				gen reg_sample = 1 if e(sample) == 1
						
	
						* Local area*Bank + Time fixed-effects
						eststo r`regnum': reghdfe d_LTI pol_Mshare policy Mshare $bank_controls $loan_controls if time <= `y' & reg_sample == 1 & treated_sd == 0, absorb(localauth_group time) vce(cluster localauth_3 group_time) 
							quietly estadd local borr_controls "Yes": r`regnum'
							quietly estadd local bank_controls "Yes": r`regnum'
							quietly estadd local fixed_lb "Yes": r`regnum'
							quietly estadd local fixed_t "Yes": r`regnum'
							local regnum = `regnum' + 1	
						* Local area*Bank + Time fixed-effects
						eststo r`regnum': reghdfe d_LTI post_unconstrained_high_Mshare post_unconstrained_interm_Mshare  post_unconstrained_low_Mshare post_unconstrained_high post_unconstrained_interm post_unconstrained_low unconstrained_interm_Mshare unconstrained_low_Mshare unconstrained_high unconstrained_low unconstrained_interm Mshare $bank_controls $loan_controls if time <= `y' & reg_sample == 1 & treated_sd == 0, absorb(localauth_group time) vce(cluster localauth_3 group_time) 
							quietly estadd local borr_controls "Yes": r`regnum'
							quietly estadd local bank_controls "Yes": r`regnum'
							quietly estadd local fixed_lb "Yes": r`regnum'
							quietly estadd local fixed_t "Yes": r`regnum'
							local regnum = `regnum' + 1
						
							
				drop reg_sample
				
				* Sample of high LTI loans
				reghdfe d_income_1_v2 pol_Mshare policy Mshare $bank_controls $loan_controls if time <= `y' & treated_sd == 0 & d_LTI == 1, absorb(localauth_group time) vce(cluster localauth_3 group_time) 
				gen reg_sample = 1 if e(sample) == 1
				
					
						* Local area*Bank + Time fixed-effects
						eststo r`regnum': reghdfe d_income_1_v2 pol_Mshare policy Mshare $bank_controls $loan_controls if time <= `y' & reg_sample == 1 & treated_sd == 0 & d_LTI == 1, absorb(localauth_group lacode_float time) vce(cluster localauth_3 group_time) 
							quietly estadd local borr_controls "Yes": r`regnum'
							quietly estadd local bank_controls "Yes": r`regnum'
							quietly estadd local fixed_lb "Yes": r`regnum'
							quietly estadd local fixed_t "Yes": r`regnum'
							local regnum = `regnum' + 1
						* Local area*Bank + Time fixed-effects
						eststo r`regnum': reghdfe d_income_1_v2 post_unconstrained_high_Mshare post_unconstrained_interm_Mshare  post_unconstrained_low_Mshare post_unconstrained_high post_unconstrained_interm post_unconstrained_low unconstrained_interm_Mshare unconstrained_low_Mshare unconstrained_high unconstrained_low unconstrained_interm Mshare $bank_controls $loan_controls if time <= `y' & reg_sample == 1 & treated_sd == 0 & d_LTI == 1, absorb(localauth_group time) vce(cluster localauth_3 group_time) 
							quietly estadd local borr_controls "Yes": r`regnum'
							quietly estadd local bank_controls "Yes": r`regnum'
							quietly estadd local fixed_lb "Yes": r`regnum'
							quietly estadd local fixed_t "Yes": r`regnum'
							local regnum = `regnum' + 1	
					
					drop reg_sample
				
				
						
			
				}
			}
			
			#delimit ;
			esttab r1 r2 r3 r4 using Table_5.tex, label replace nonotes se keep(pol_Mshare post_unconstrained_high_Mshare post_unconstrained_interm_Mshare post_unconstrained_low_Mshare) booktabs
			s(N r2 borr_controls bank_controls fixed_lb fixed_t,label("Observations" "\(R^{2}\)" "Borrower, Loan Controls" "Bank Controls" "Local area\$\times\$Bank FE" "Time FE")) 
			mgroups("\$\leftarrow\mbox{High LTI Dummy}\rightarrow\$" "\$\leftarrow\mbox{Low-income Dummy}\rightarrow\$", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) lhs("Variable")) 
			nodepvars;
			#delimit cr	

		}
		
		* Table 6
		{
		    
			foreach y in 225 {
				foreach x in sd {
					
					local regnum = 1	
				
					reghdfe interest pol_hLTI policy d_LTI $bank_controls $loan_controls if time <= `y' & treated_sd == 0, absorb(localauth_group time) vce(cluster localauth_3 group_time) 
					gen reg_sample = 1 if e(sample) == 1
							
							eststo r`regnum': reghdfe interest pol_hLTI policy d_LTI $bank_controls $loan_controls_LTV if time <= `y' & reg_sample == 1 & treated_sd == 0, absorb(localauth_group time) vce(cluster localauth_3 group_time) 
								quietly estadd local borr_controls "Yes": r`regnum'
								quietly estadd local bank_controls "Yes": r`regnum'
								quietly estadd local fixed_lb "Yes": r`regnum'
								quietly estadd local fixed_t "Yes": r`regnum'
								local regnum = `regnum' + 1
							eststo r`regnum': reghdfe interest post_unconstrained_high_hLTI post_unconstrained_interm_hLTI post_unconstrained_low_hLTI post_unconstrained_high post_unconstrained_interm post_unconstrained_low unconstrained_interm_hLTI unconstrained_low_hLTI unconstrained_high unconstrained_low unconstrained_interm d_LTI $bank_controls $loan_controls_LTV if time <= `y' & reg_sample == 1 & treated_sd == 0, absorb(localauth_group time) vce(cluster localauth_3 group_time) 
								quietly estadd local borr_controls "Yes": r`regnum'
								quietly estadd local bank_controls "Yes": r`regnum'
								quietly estadd local fixed_lb "Yes": r`regnum'
								quietly estadd local fixed_t "Yes": r`regnum'
								local regnum = `regnum' + 1	
								
							
							eststo r`regnum': reghdfe interest pol_hLTI policy d_LTI $bank_controls $loan_controls_LTV if time <= `y' & reg_sample == 1 & treated_sd == 0 & dtr75 == 1, absorb(localauth_group time) vce(cluster localauth_3 group_time) 
								quietly estadd local borr_controls "Yes": r`regnum'
								quietly estadd local bank_controls "Yes": r`regnum'
								quietly estadd local fixed_lb "Yes": r`regnum'
								quietly estadd local fixed_t "Yes": r`regnum'
								local regnum = `regnum' + 1
							eststo r`regnum': reghdfe interest pol_hLTI policy d_LTI $bank_controls $loan_controls_LTV if time <= `y' & reg_sample == 1 & treated_sd == 0 & dtr75 == 0, absorb(localauth_group time) vce(cluster localauth_3 group_time) 
								quietly estadd local borr_controls "Yes": r`regnum'
								quietly estadd local bank_controls "Yes": r`regnum'
								quietly estadd local fixed_lb "Yes": r`regnum'
								quietly estadd local fixed_t "Yes": r`regnum'
								local regnum = `regnum' + 1		
							
							
					drop reg_sample	
										
				}
			}
				
				#delimit ;
				esttab r1 r2 r3 r4 using Table_6.tex, label replace nonotes se keep(pol_hLTI post_unconstrained_high_hLTI post_unconstrained_interm_hLTI post_unconstrained_low_hLTI) booktabs
				s(N r2 borr_controls bank_controls fixed_lb fixed_t,label("Observations" "\(R^{2}\)" "Borrower, Loan Controls" "Bank Controls" "Local area\$\times\$Bank FE" "Time FE")) 
				mgroups("\$\leftarrow\mbox{Interest rate}\rightarrow\$", pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) lhs("Variable"))
				mlabels("Full" "High share" "Low share", pattern(1 0 1 1)) nonumbers nodepvars;
				#delimit cr	
				
				* clear estimates
				eststo clear
			
		}
		
		* Table 7
		{
		    
			foreach y in 225 {
				foreach x in sd {
					
					local regnum = 1	
				
					reghdfe interest pol_lowinc policy d_income_1_v2 $bank_controls $loan_controls if time <= `y' & treated_sd == 0 & d_LTI == 1, absorb(localauth_group time) vce(cluster localauth_3 group_time) 
					gen reg_sample = 1 if e(sample) == 1
						
							eststo r`regnum': reghdfe interest pol_lowinc policy d_income_1_v2 $bank_controls $loan_controls_LTV if time <= `y' & reg_sample == 1 & treated_sd == 0 & d_LTI == 1, absorb(localauth_group time) vce(cluster localauth_3 group_time) 
								quietly estadd local borr_controls "Yes": r`regnum'
								quietly estadd local bank_controls "Yes": r`regnum'
								quietly estadd local fixed_lb "Yes": r`regnum'
								quietly estadd local fixed_t "Yes": r`regnum'
								local regnum = `regnum' + 1
							eststo r`regnum': reghdfe interest post_unconstrained_high_lowinc post_unconstrained_interm_lowinc post_unconstrained_low_lowinc post_unconstrained_high post_unconstrained_interm post_unconstrained_low unconstrained_interm_lowinc unconstrained_low_lowinc unconstrained_high unconstrained_low unconstrained_interm d_income_1_v2 $bank_controls $loan_controls_LTV if time <= `y' & reg_sample == 1 & treated_sd == 0 & d_LTI == 1, absorb(localauth_group time) vce(cluster localauth_3 group_time) 
								quietly estadd local borr_controls "Yes": r`regnum'
								quietly estadd local bank_controls "Yes": r`regnum'
								quietly estadd local fixed_lb "Yes": r`regnum'
								quietly estadd local fixed_t "Yes": r`regnum'
								local regnum = `regnum' + 1	
								
							eststo r`regnum': reghdfe interest pol_lowinc policy d_income_1_v2 $bank_controls $loan_controls_LTV if time <= `y' & reg_sample == 1 & treated_sd == 0 & d_LTI == 1 & dtr75 == 1, absorb(localauth_group time) vce(cluster localauth_3 group_time) 
								quietly estadd local borr_controls "Yes": r`regnum'
								quietly estadd local bank_controls "Yes": r`regnum'
								quietly estadd local fixed_lb "Yes": r`regnum'
								quietly estadd local fixed_t "Yes": r`regnum'
								local regnum = `regnum' + 1
							eststo r`regnum': reghdfe interest pol_lowinc policy d_income_1_v2 $bank_controls $loan_controls_LTV if time <= `y' & reg_sample == 1 & treated_sd == 0 & d_LTI == 1 & dtr75 == 0, absorb(localauth_group time) vce(cluster localauth_3 group_time) 
								quietly estadd local borr_controls "Yes": r`regnum'
								quietly estadd local bank_controls "Yes": r`regnum'
								quietly estadd local fixed_lb "Yes": r`regnum'
								quietly estadd local fixed_t "Yes": r`regnum'
								local regnum = `regnum' + 1	
								
							eststo r`regnum': reghdfe interest post_unconstrained_high_lowinc post_unconstrained_interm_lowinc post_unconstrained_low_lowinc post_unconstrained_high post_unconstrained_interm post_unconstrained_low unconstrained_interm_lowinc unconstrained_low_lowinc unconstrained_high unconstrained_low unconstrained_interm d_income_1_v2 $bank_controls $loan_controls_LTV if time <= `y' & reg_sample == 1 & treated_sd == 0 & d_LTI == 1 & dtr75 == 1, absorb(localauth_group time) vce(cluster localauth_3 group_time) 
								quietly estadd local borr_controls "Yes": r`regnum'
								quietly estadd local bank_controls "Yes": r`regnum'
								quietly estadd local fixed_lb "Yes": r`regnum'
								quietly estadd local fixed_t "Yes": r`regnum'
								local regnum = `regnum' + 1		
							
					drop reg_sample	
										
				}
			}		
				
				#delimit ;
				esttab r1 r2 r3 r4 r5 using Table_7.tex, label replace nonotes se keep(pol_lowinc post_unconstrained_high_lowinc post_unconstrained_interm_lowinc post_unconstrained_low_lowinc) booktabs
				s(N r2 borr_controls bank_controls fixed_lb fixed_t,label("Observations" "\(R^{2}\)" "Borrower, Loan Controls" "Bank Controls" "Local area\$\times\$Bank FE" "Time FE")) 
				mgroups("\$\leftarrow\mbox{Interest rate}\rightarrow\$", pattern(1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) lhs("Variable"))
				mlabels("Full" "High share" "Low share" "High share" "Low share", pattern(1 0 1 1 1 1)) nonumbers nodepvars;
				#delimit cr
				
				* clear estimates
				eststo clear

		}
			
		* Table 8
		{
		    
			foreach y in 225 {
				foreach x in sd {	
				
					reghdfe interest pol_lowinc policy d_income_1_v2 $bank_controls $loan_controls if time <= `y' & treated_sd == 0 & d_LTI == 1, absorb(localauth_group lacode_float time) vce(cluster localauth_3 group_time) 
					gen reg_sample = 1 if e(sample) == 1
					
					foreach subsample in all highlti_lowinc {
						
						* Initialize for each subsample
						local regnum = 1
						
						foreach subsample_value of numlist 1 2 {
						 
															
							eststo r`regnum': reghdfe interest pol_lowinc policy d_income_1_v2 $bank_controls $loan_controls_LTV if time <= `y' & reg_sample == 1 & treated_sd == 0 & d_LTI == 1 & unconstr_2q_`subsample' == `subsample_value', absorb(localauth_group time) vce(cluster localauth_3 group_time) 
								quietly estadd local borr_controls "Yes": r`regnum'
								quietly estadd local bank_controls "Yes": r`regnum'
								quietly estadd local fixed_lb "Yes": r`regnum'
								quietly estadd local fixed_t "Yes": r`regnum'
								local regnum = `regnum' + 1
							eststo r`regnum': reghdfe interest pol_lowinc policy d_income_1_v2 $bank_controls $loan_controls_LTV if time <= `y' & reg_sample == 1 & treated_sd == 0 & d_LTI == 1 & unconstr_2q_`subsample' == `subsample_value' & dtr50 == 1, absorb(localauth_group lacode_float time) vce(cluster localauth_3 group_time) 
								quietly estadd local borr_controls "Yes": r`regnum'
								quietly estadd local bank_controls "Yes": r`regnum'
								quietly estadd local fixed_lb "Yes": r`regnum'
								quietly estadd local fixed_t "Yes": r`regnum'
								local regnum = `regnum' + 1
							eststo r`regnum': reghdfe interest pol_lowinc policy d_income_1_v2 $bank_controls $loan_controls_LTV if time <= `y' & reg_sample == 1 & treated_sd == 0 & d_LTI == 1 & unconstr_2q_`subsample' == `subsample_value' & dtr50 == 0, absorb(localauth_group lacode_float time) vce(cluster localauth_3 group_time) 
								quietly estadd local borr_controls "Yes": r`regnum'
								quietly estadd local bank_controls "Yes": r`regnum'
								quietly estadd local fixed_lb "Yes": r`regnum'
								quietly estadd local fixed_t "Yes": r`regnum'
								local regnum = `regnum' + 1	
						
						* close loop for subsample_value
						}
						
						#delimit ;
						esttab r1 r4 r2 r5 r3 r6 using Table_8.tex, label replace nonotes se keep(pol_lowinc) booktabs
						s(N r2 borr_controls bank_controls fixed_lb fixed_t,label("Observations" "\(R^{2}\)" "Borrower, Loan Controls" "Bank Controls" "Local area\$\times\$Bank FE" "Time FE" )) 
						mgroups("\$\leftarrow\mbox{Interest rate}\rightarrow\$", pattern(1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) lhs("Variable"));
						#delimit cr	

						* clear estimates
						eststo clear
						
					* close loop for subsample	
					}	
							
					drop reg_sample	
	
				}
			}
			
		}
		
		
		* Figure 1B
		reghdfe d_LTI i.policy i.treated_sd time_treated1-time_treated7 time_treated10-time_treated16 $bank_controls $loan_controls if time <= 225, absorb(time localauth_group) vce(cluster localauth_3 group_time) 
		est store beta_time_treated
		coefplot beta_time_treated, keep(time_treated*) levels(95) vertical coeflabels(, labsize(vsmall)) ylabel(-0.2(0.1)0.2, nogrid angle(0) labsize(vsmall)) yline(0, lpattern(dash)) ///
			plotregion(fcolor(white) lcolor(white)) graphregion(fcolor(white) lcolor(white)) msymbol(d) addplot(scatteri -0.2 7.5 0.2 7.5, lc(maroon) lp(dash) msymbol(i) recast(connected))
			graph export betat_hlti.pdf, as(pdf) replace

		
		* Figure 2
		foreach nuts in 2 {
						
						reghdfe d_income_1_v`nuts' i.policy i.treated_sd time_treated1-time_treated7 time_treated10-time_treated16 $bank_controls $loan_controls if d_LTI == 1 & time <= 225, absorb(time localauth_group) vce(cluster localauth_3 group_time)
						est store beta_time_treated3
						coefplot beta_time_treated3, keep(time_treated*) levels(95) vertical coeflabels(, labsize(vsmall)) ylabel(-0.2(0.1)0.2, angle(0) labsize(vsmall) nogrid) yline(0, lpattern(dash)) ///
						plotregion(fcolor(white) lcolor(white)) graphregion(fcolor(white) lcolor(white)) msymbol(d) addplot(scatteri -0.2 7.5 0.2 7.5, lc(maroon) lp(dash) msymbol(i) recast(connected))
						graph export betat_hlti_linc_v`nuts'.pdf, as(pdf) replace
						
					}
		
		*** SUMMARY STATISTIC
			
		reghdfe d_LTI i.policy##i.treated_sd $bank_controls $loan_controls if time <= 225, absorb(time localauth_group) vce(cluster localauth_3 group_time) 
		gen reg_sample = 1 if e(sample) == 1
		
		estpost tabstat loan_val property_val mortgage_term  LTI LTV gross_income age_borrower interest stress_rate if reg_sample == 1, stat(count mean sd min p25 p50 p75 p90 max) columns(statistics)
		est sto full
		
		*
			esttab Table_1_toppanel using fullsample, replace label ///
			cell("count mean(fmt(%10.0fc %10.0fc %5.2fc %5.2fc %5.1fc %10.0fc %5.2fc %5.2fc %5.2fc)) sd(fmt(%10.0fc %10.0fc %5.2fc %5.2fc %5.1fc %10.0fc %5.2fc %5.2fc %5.2fc)) min(fmt(%10.0fc %10.0fc %5.2fc %5.2fc %5.1fc %10.0fc %5.2fc %5.2fc %5.2fc)) p25(fmt(%10.0fc %10.0fc %5.2fc %5.2fc %5.1fc %10.0fc %5.2fc %5.2fc %5.2fc)) p50(fmt(%10.0fc %10.0fc %5.2fc %5.2fc %5.1fc %10.0fc %5.2fc %5.2fc %5.2fc)) p75(fmt(%10.0fc %10.0fc %5.2fc %5.2fc %5.1fc %10.0fc %5.2fc %5.2fc %5.2fc)) max(fmt(%10.0fc %10.0fc %5.2fc %5.2fc %5.1fc %10.0fc %5.2fc %5.2fc %5.2fc))") ///
			tex title("Summary Statistics for loan-level data") nonumbers
			
		
	reghdfe d_LTI i.policy##i.treated_sd $bank_controls $loan_controls if time <= 225 & d_LTI == 1, absorb(time localauth_group) vce(cluster localauth_3 group_time) 
		gen reg_sample_hlti = 1 if e(sample) == 1	
	
	estpost tabstat loan_val property_val mortgage_term  LTI LTV gross_income age_borrower interest stress_rate if reg_sample_hlti == 1, stat(count mean sd min p25 p50 p75 p90 max) columns(statistics)
	est sto full_hlti
			
			*
			esttab Table_1_bottompanel using fullsample_hlti, replace label ///
			cell("count mean(fmt(%10.0fc %10.0fc %5.2fc %5.2fc %5.1fc %10.0fc %5.2fc %5.2fc %5.2fc)) sd(fmt(%10.0fc %10.0fc %5.2fc %5.2fc %5.1fc %10.0fc %5.2fc %5.2fc %5.2fc)) min(fmt(%10.0fc %10.0fc %5.2fc %5.2fc %5.1fc %10.0fc %5.2fc %5.2fc %5.2fc)) p25(fmt(%10.0fc %10.0fc %5.2fc %5.2fc %5.1fc %10.0fc %5.2fc %5.2fc %5.2fc)) p50(fmt(%10.0fc %10.0fc %5.2fc %5.2fc %5.1fc %10.0fc %5.2fc %5.2fc %5.2fc)) p75(fmt(%10.0fc %10.0fc %5.2fc %5.2fc %5.1fc %10.0fc %5.2fc %5.2fc %5.2fc)) max(fmt(%10.0fc %10.0fc %5.2fc %5.2fc %5.1fc %10.0fc %5.2fc %5.2fc %5.2fc))") ///
			tex title("Summary Statistics for high LTI mortgages") nonumbers frag	
			
			
		
		************************************************************************
		

		
		
		
		